/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.base.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.chlitina.store.common.persistence.BaseEntity;
import com.chlitina.store.modules.sys.entity.Store;
import com.google.common.collect.Lists;

/**
 * 客户组管理Entity
 * @author lvbo
 * @version 2013-07-23
 */
@Entity
@Table(name = "customer_group")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class CustomerGroup extends BaseEntity {
	
	private static final long serialVersionUID = 1L;
	private Long id; 		// 编号
	private String groupName; 	// 名称
	private Store store; // 门店

	private List<CustomerGroupDetail> customerGroupDetailList = Lists.newArrayList();
	public CustomerGroup() {
	}

	public CustomerGroup(Long id){
		this();
		this.id = id;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	//@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_base_customerGroup")
	//@SequenceGenerator(name = "seq_base_customerGroup", sequenceName = "seq_base_customerGroup")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name="group_name")
	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	@ManyToOne(cascade={CascadeType.REFRESH}, fetch = FetchType.LAZY) 
	@JoinColumn(name="store_id")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@NotNull
	public Store getStore() {
		return store;
	}

	public void setStore(Store store) {
		this.store = store;
	}
	
	@OneToMany(cascade={CascadeType.REFRESH, CascadeType.MERGE},fetch=FetchType.LAZY,mappedBy="customerGroup")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<CustomerGroupDetail> getCustomerGroupDetailList() {
		return customerGroupDetailList;
	}

	public void setCustomerGroupDetailList(
			List<CustomerGroupDetail> customerGroupDetailList) {
		this.customerGroupDetailList = customerGroupDetailList;
	}
	
}


